package com.sdhs.projectstart.controller;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.SecurityUtils;
import com.sdhs.projectstart.domain.ProjectDept;
import com.sdhs.projectstart.service.IProjectDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目组建信息操作处理
 *
 * @author ww
 */
@RestController
@RequestMapping("/projectStart/dept")
public class ProjectDeptController extends BaseController {
    @Autowired
    private IProjectDeptService projectDeptService;

    /**
     * 查询项目组列表
     */
    @PreAuthorize("@ss.hasPermi('projectStart:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectDept projectDept) {
        startPage();
        List<ProjectDept> list = projectDeptService.selectProjectDeptList(projectDept);
        return getDataTable(list);
    }

    /**
     * 获取项目进度控制--竣工详细信息
     */
    @PreAuthorize("@ss.hasPermi('projectStart:dept:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(projectDeptService.selectProjectDeptById(id));
    }

    /**
     * 新增项目组
     */
    @PreAuthorize("@ss.hasPermi('projectStart:dept:add')")
    @Log(title = "项目组建", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectDept projectDept) {
        projectDept.setApplicant(SecurityUtils.getNickName());
        return success(projectDeptService.insertProjectDept(projectDept));
    }

    /**
     * 修改项目组
     */
    @PreAuthorize("@ss.hasPermi('projectStart:dept:edit')")
    @Log(title = "项目组建", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectDept projectDept) {
        return toAjax(projectDeptService.updateProjectDept(projectDept));
    }

    /**
     * 删除项目组
     */
    @PreAuthorize("@ss.hasPermi('projectStart:dept:remove')")
    @Log(title = "项目组建", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(projectDeptService.deleteProjectDeptByIds(ids));
    }
}
